﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace NestedListBoxDemo
{
    public class SubItem
    {
        public string Name { get; set; }
        public string Description { get; set; }
    }

    public class ParentItem
    {
        public string Title { get; set; }
        public List<SubItem> SubItems { get; set; }
    }

    public class MainViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<ParentItem> ParentItems { get; set; }

        private ParentItem _selectedItem;
        public ParentItem SelectedItem
        {
            get => _selectedItem;
            set
            {
                _selectedItem = value;
                OnPropertyChanged(nameof(SelectedItem));
            }
        }

        public MainViewModel()
        {
            ParentItems = new ObservableCollection<ParentItem>
            {
            new ParentItem
            {
                Title = "Parent 1",
                SubItems = new List<SubItem>
                {
                    new SubItem { Name = "Child 1.1", Description = "Description 1.1" },
                    new SubItem { Name = "Child 1.2", Description = "Description 1.2" }
                }
            },
            new ParentItem
            {
                Title = "Parent 2",
                SubItems = new List<SubItem>
                {
                    new SubItem { Name = "Child 2.1", Description = "Description 2.1" },
                    new SubItem { Name = "Child 2.2", Description = "Description 2.2" }
                }
            }
        };
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
